testsuite: Add png and tiff methods
authorBenjamin Otte <otte@redhat.com>
Tue, 14 Sep 2021 00:37:50 +0000 (02:37 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 22:25:22 +0000 (00:25 +0200)
We encode the texture to a PNG or TIFF and then decode
it again, in various ways.

testsuite/gdk/memorytexture.c

index 021a7ad11b06a9b8925ef1f774cfc97b4e4942b4..020d6927e49c2c3dad9669a73b22403f6233eb88 100644 (file)
@@ -12,6 +12,10 @@ typedef enum {
   TEXTURE_METHOD_LOCAL,
   TEXTURE_METHOD_GL,
   TEXTURE_METHOD_GL_RELEASED,
+  TEXTURE_METHOD_PNG,
+  TEXTURE_METHOD_PNG_PIXBUF,
+  TEXTURE_METHOD_TIFF,
+  TEXTURE_METHOD_TIFF_PIXBUF,
 
   N_TEXTURE_METHODS
 } TextureMethod;
@@ -448,6 +452,68 @@ create_texture (GdkMemoryFormat  format,
       gdk_gl_texture_release (GDK_GL_TEXTURE (texture));
       break;
 
+    case TEXTURE_METHOD_PNG:
+      {
+        GBytes *bytes = gdk_texture_save_to_png_bytes (texture);
+        g_assert (bytes);
+        g_object_unref (texture);
+        texture = gdk_texture_new_from_bytes (bytes, NULL);
+        g_assert (texture);
+        g_bytes_unref (bytes);
+      }
+      break;
+
+    case TEXTURE_METHOD_PNG_PIXBUF:
+      {
+        GInputStream *stream;
+        GdkPixbuf *pixbuf;
+        GBytes *bytes;
+
+        bytes = gdk_texture_save_to_png_bytes (texture);
+        g_assert (bytes);
+        g_object_unref (texture);
+        stream = g_memory_input_stream_new_from_bytes (bytes);
+        pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+        g_object_unref (stream);
+        g_assert (pixbuf);
+        texture = gdk_texture_new_for_pixbuf (pixbuf);
+        g_assert (texture);
+        g_object_unref (pixbuf);
+        g_bytes_unref (bytes);
+      }
+      break;
+
+    case TEXTURE_METHOD_TIFF:
+      {
+        GBytes *bytes = gdk_texture_save_to_tiff_bytes (texture);
+        g_assert (bytes);
+        g_object_unref (texture);
+        texture = gdk_texture_new_from_bytes (bytes, NULL);
+        g_assert (texture);
+        g_bytes_unref (bytes);
+      }
+      break;
+
+    case TEXTURE_METHOD_TIFF_PIXBUF:
+      {
+        GInputStream *stream;
+        GdkPixbuf *pixbuf;
+        GBytes *bytes;
+
+        bytes = gdk_texture_save_to_png_bytes (texture);
+        g_assert (bytes);
+        g_object_unref (texture);
+        stream = g_memory_input_stream_new_from_bytes (bytes);
+        pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+        g_object_unref (stream);
+        g_assert (pixbuf);
+        texture = gdk_texture_new_for_pixbuf (pixbuf);
+        g_assert (texture);
+        g_object_unref (pixbuf);
+        g_bytes_unref (bytes);
+      }
+      break;
+
     case N_TEXTURE_METHODS:
     default:
       g_assert_not_reached ();
@@ -584,7 +650,7 @@ add_test (const char    *name,
     {
       for (method = 0; method < N_TEXTURE_METHODS; method++)
         {
-          const char *method_names[N_TEXTURE_METHODS] = { "local", "gl", "gl-released" };
+          const char *method_names[N_TEXTURE_METHODS] = { "local", "gl", "gl-released", "png", "png-pixbuf", "tiff", "tiff-pixbuf" };
           char *test_name = g_strdup_printf ("%s/%s/%s",
                                              name,
                                              g_enum_get_value (enum_class, format)->value_nick,